package com.wfs.service.impl;

import com.wfs.mapper.UserMapper;
import com.wfs.pojo.Result;
import com.wfs.pojo.User;
import com.wfs.service.UserService;
import com.wfs.utils.Md5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public User findByUsername(String username) {
        // 根据用户名从数据库查找
        User user = userMapper.findByUsername(username);
        return user;
    }

    @Override
    public void save(String username, String password) {
        // 密码加密
        String md5Str = Md5Util.getMD5String(password);
        // 调用userMapper的save方法保存用户信息
        userMapper.save(username, md5Str);
    }

    @Override
    public void update(User user) {
        userMapper.update(user);
    }

    @Override
    public void updateAvatar(String avatarUrl, Integer userId) {
        userMapper.updateAvatar(avatarUrl, userId);
    }

    @Override
    public void updatePassword(String newPassword, Integer userId) {
        userMapper.updatePassword(newPassword, userId);
    }


}
